import { store } from '../stores'
import { useEffect, useState } from 'react'
import { detail } from '../type/home'

export const price = (value: number) => {
  if (value != null && value != undefined) {
    return value.toFixed(2)
  }
}
// export function monitor () {
//   const [cartList, setCartList] = useState<detail[]>([])
//   useEffect(() => {
//     // console.log(store.getState().cart)
//     setCartList(store.getState().CartStore) // console.log(store.getState().cart)
//     const unsubscrible = store.subscribe(() => {
//       setCartList(store.getState().CartStore)
//     })
//     return () => {
//       unsubscrible()
//     }
//   }, [])
// }
export const badgeNum = () => {
  const { CartStore } = store.getState()
  return CartStore.reduce((total, item) => total + (item.number as number), 0)
}
